package c04.monitor;

import lombok.extern.slf4j.Slf4j;
import util.Sleeper;

/**
 * 面试题：线程八锁
 * 结果：先输出2，1秒后输出1
 */
@Slf4j(topic = "c.Thread8Lock4")
public class Thread8Lock4 {
    static class Number {
        public synchronized void a() {
            Sleeper.sleep(1);
            log.debug("1");
        }

        public synchronized void b() {
            log.debug("2");
        }
    }

    public static void main(String[] args) {
        Number n1 = new Number();
        Number n2 = new Number();

        new Thread(() -> {
            log.debug("t1 begin");
            n1.a();
        }, "t1").start();

        new Thread(() -> {
            log.debug("t2 begin");
            n2.b();
        }, "t2").start();
    }
}
